package comentarios;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;

import daos.SessionManager;
import aterrizar.Usuario;

public class ModificarPub {
	
	private Usuario user;
	private String destino;
	
	public ModificarPub(Usuario u, String d){
		this.user = u;
		this.destino = d;
		
	}

	public void changeLikeStatus(LikeStatus ls){
		BasicDBObject query = new BasicDBObject();
		query.put("usuario", this.user.getNombreDeUsuario());
		query.put("destino", this.destino);
		
		BasicDBObject newLS = new BasicDBObject();
		newLS.put("likeStatus", ls.toString());
		
		BasicDBObject updateObj = new BasicDBObject();
		updateObj.put("$set", newLS);
		
		DBCollection collectAux = SessionManager.MongoClient().getCollection("publicaciones");
		collectAux.update(query, updateObj);
		
		
	}
	
	public void changeVisibilidad(Visibilidad vs){
		BasicDBObject query = new BasicDBObject();
		query.put("usuario", this.user.getNombreDeUsuario());
		query.put("destino", this.destino);
		
		BasicDBObject newVS = new BasicDBObject();
		newVS.put("visibilidad", vs.toString());
		
		BasicDBObject updateObj = new BasicDBObject();
		updateObj.put("$set", newVS);
		
		DBCollection collectAux = SessionManager.MongoClient().getCollection("publicaciones");
		collectAux.update(query, updateObj);
	}


	public void addComment(String cm){
		BasicDBObject query = new BasicDBObject();
		query.put("usuario", this.user.getNombreDeUsuario());
		query.put("destino", this.destino);
		
		BasicDBObject newCM = new BasicDBObject();
		newCM.put("comentarios",cm);
		
		BasicDBObject updateObj = new BasicDBObject();
		updateObj.put("$push", newCM);
		
		DBCollection collectAux = SessionManager.MongoClient().getCollection("publicaciones");
		collectAux.update(query, updateObj);
	}
	
}
	

